package com.pand.model.user;

import com.pand.model.BaseObject;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @ClassName: Role
 * @Description: 角色
 *
 */
@Entity
@Table(name = "SYS_ROLE")
@SequenceGenerator(name = "SeqRole", sequenceName = "SEQ_ROLE", allocationSize = 1)
public class Role extends BaseObject {

   /**
    * @Fields serialVersionUID :
    */
   private static final long serialVersionUID = 1L;

   /**
    * 主键
    */
   private Long id;

   /**
    * 角色名称
    */
   private String roleName;

   /**
    * 角色描述
    */
   private String roleDesc;

   /**
    * 所属组织
    */
   private Long orgId;


   /**
    * 权限列表
    */
   private List<Privilege> privileges=new ArrayList<Privilege>();

   /**
    * 菜单列表
    */
   private List<Menu> menus=new ArrayList<Menu>();

   @Id
   @GeneratedValue(generator = "SeqRole")
   @Column(name = "ID")
   public Long getId() {
       return id;
   }
   public void setId(Long id) {
       this.id = id;
   }
   @Column(name = "ROLE_NAME")
   public String getRoleName() {
       return roleName;
   }
   public void setRoleName(String roleName) {
       this.roleName = roleName;
   }
   @Column(name = "ROLE_DESC")
   public String getRoleDesc() {
       return roleDesc;
   }
   public void setRoleDesc(String roleDesc) {
       this.roleDesc = roleDesc;
   }

   @ManyToMany(
           targetEntity=com.pand.model.user.Privilege.class,
           cascade ={CascadeType.PERSIST,CascadeType.MERGE},
           fetch=FetchType.LAZY )
   @JoinTable(name="SYS_ROLE_PRIVILEGE",
              joinColumns={@JoinColumn(name="ROLE_ID")},
              inverseJoinColumns={@JoinColumn(name="PRIVILEGE_ID")})
   public List<Privilege> getPrivileges() {
       return privileges;
   }

   @ManyToMany(
           targetEntity=com.pand.model.user.Menu.class,
           cascade ={CascadeType.PERSIST,CascadeType.MERGE},
           fetch=FetchType.LAZY )
   @JoinTable(name="SYS_ROLE_MENU",
              joinColumns={@JoinColumn(name="ROLE_ID")},
              inverseJoinColumns={@JoinColumn(name="MENU_ID")})
   @OrderBy("mdesc asc")
   public List<Menu> getMenus(){
       return menus;
   }

   public void setMenus(List<Menu> menus){
       this.menus=menus;
   }

   public void setPrivileges(List<Privilege> privileges) {
       this.privileges = privileges;
   }
   @Column(name = "ORG_ID")
   public Long getOrgId() {
       return orgId;
   }
   public void setOrgId(Long orgId) {
       this.orgId = orgId;
   }

}
